home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Technology Seed / ADC Seed CD - July 1999.toast / Carbon SDK 1.0d10c3 / Sample Code / AppearanceSample / StandardAlert.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-01  |  7.6 KB  |  258 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        StandardAlert.c
  3.  
  4.     Contains:    Sample code showing the use of StandardAlert.
  5.  
  6.     Version:    Appearance 1.0 SDK
  7.  
  8.     Copyright:    © 1997 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                Edward Voas
  13.  
  14.         Other Contact:        7 of 9, Borg Collective
  15.  
  16.         Technology:            OS Technologies Group
  17.  
  18.     Writers:
  19.  
  20.         (edv)    Ed Voas
  21.  
  22.     Change History (most recent first):
  23.  
  24.          <3>    12/17/97    edv        Move comment to the right place!
  25.          <2>     10/1/97    edv        Add comment for ModalDialog call.
  26.          <1>     9/11/97    edv        First checked in.
  27. */
  28.  
  29. #include "AppearanceSamplePrefix.h"
  30.  
  31. #include <Appearance.h>
  32. #include "UDialogUtils.h"
  33.  
  34. //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  35. //    Dialog Item numbers
  36. //ãããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  37.  
  38. enum
  39. {
  40.     kOKButton            = 1,
  41.     kCancelButton        = 2,
  42.     kErrorText            = 4,
  43.     kExplainText        = 6,
  44.     kMovableCheck        = 7,
  45.     kButtonGroup        = 8,
  46.     kButton1Group        = 9,
  47.     kButton2Group        = 10,
  48.     kButton3Group        = 11,
  49.     kButton2Check        = 13,
  50.     kButton3Check        = 14,
  51.     kUseDefault1Check    = 15,
  52.     kUseDefault2Check    = 16,
  53.     kUseDefault3Check    = 17,
  54.     kButton1Text        = 18,
  55.     kButton2Text        = 19,
  56.     kButton3Text        = 20,
  57.     kTypePopup            = 22,
  58.     kHelpCheck            = 23
  59. };
  60.  
  61. void    TestStandardAlert();
  62.  
  63. //ããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  64. //    Ä TestStandardAlert
  65. //ããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  66. //    This routine puts up an alert using the StandardAlert routine. It first
  67. //    requests information via a dialog. It uses a 'dlog' resource for this
  68. //    dialog and has embedding enabled. After reviewing the DITL in ResEdit
  69. //    and looking at the code below, it should provide some good clues as to
  70. //    how you can take advantage of embedding features. You'll notice that I've
  71. //    used it implicity below when I disable the contents of the secondary
  72. //    groups containing the 'Use Default' check box and the button name edit
  73. //    text box. This allows me to properly save the state of the Use Default
  74. //    check box when checking and unchecking the 'Button <n>' check boxes. If I
  75. //    had the 'Use Default' check box off when I click the Button 2 check box
  76. //    off, the next time I turn the Button 2 check box on, the Use Default button
  77. //    will still be enabled.
  78. //
  79. //    You'll also notice just how easy it is to disable edit text fields here.
  80. //    Its just a call to the utility to enable/disable a dialog item. When in
  81. //    embedding mode, all items are controls, so you can treat everything the
  82. //    same way!
  83. //
  84. //    This routine also shows an example of the SetControlFontStyle routine,
  85. //    which allows you to set the font of any control that supports font
  86. //    styles. All new controls delivered with appearance that display text
  87. //    obey the new font style doodad. Alternatively, we could have created a
  88. //    'dftb' resource to set the font styles.
  89. //
  90. void
  91. TestStandardAlert()
  92. {
  93.     DialogPtr        dialog;
  94.     SInt16            itemHit;
  95.     Str255            text, desc;
  96.     Str63            button1Text, button2Text, button3Text;
  97.     StringPtr        btn1, btn2, btn3;
  98.     Boolean            movable;
  99.     SInt16            alertType;
  100.     ControlFontStyleRec    style;
  101.     Boolean            useHelp;
  102.     AlertStdAlertParamRec    param;
  103.     
  104.     dialog = GetNewDialog( 1000, nil, (WindowPtr)-1L );
  105.     if ( dialog == nil ) return;
  106.     
  107.     SetDialogDefaultItem( dialog, kOKButton );
  108.     SetDialogCancelItem( dialog, kCancelButton );
  109.     
  110.     SelectDialogItemText( dialog, kErrorText, 0, 32768 );
  111.     
  112.     UDialogUtils::ToggleCheckBox( dialog, kUseDefault1Check );
  113.     UDialogUtils::ToggleCheckBox( dialog, kUseDefault2Check );
  114.     UDialogUtils::ToggleCheckBox( dialog, kUseDefault3Check );
  115.  
  116.     UDialogUtils::EnableDialogItem( dialog, kButton1Text, false );
  117.     UDialogUtils::EnableDialogItem( dialog, kButton2Text, false );
  118.     UDialogUtils::EnableDialogItem( dialog, kButton3Text, false );
  119.  
  120.     UDialogUtils::EnableDialogItem( dialog, kButton2Group, false );
  121.     UDialogUtils::EnableDialogItem( dialog, kButton3Group, false );
  122.  
  123.     style.flags = kControlUseFontMask;
  124.     style.font = kControlFontSmallBoldSystemFont;
  125.     UDialogUtils::SetFontStyle( dialog, kButtonGroup, style );
  126.  
  127.     ShowWindow( GetDialogWindow( dialog ) );
  128.     
  129.     itemHit = 0;
  130.     while ( itemHit != kOKButton && itemHit != kCancelButton )
  131.     {
  132.         ModalDialog( nil, &itemHit );
  133.         
  134.         switch ( itemHit )
  135.         {
  136.             case kMovableCheck:
  137.             case kHelpCheck:
  138.                 UDialogUtils::ToggleCheckBox( dialog, itemHit );
  139.                 break;
  140.             
  141.             case kButton2Check:
  142.                 UDialogUtils::ToggleCheckBox( dialog, kButton2Check );
  143.                 if ( UDialogUtils::GetItemValue( dialog, kButton2Check ) == 0 )
  144.                     UDialogUtils::EnableDialogItem( dialog, kButton2Group, false );
  145.                 else
  146.                     UDialogUtils::EnableDialogItem( dialog, kButton2Group, true );
  147.                 break;
  148.             
  149.             case kButton3Check:
  150.                 UDialogUtils::ToggleCheckBox( dialog, kButton3Check );
  151.                 if ( UDialogUtils::GetItemValue( dialog, kButton3Check ) == 0 )
  152.                     UDialogUtils::EnableDialogItem( dialog, kButton3Group, false );
  153.                 else
  154.                     UDialogUtils::EnableDialogItem( dialog, kButton3Group, true );
  155.                 break;
  156.             
  157.             case kUseDefault1Check:
  158.                 UDialogUtils::ToggleCheckBox( dialog, kUseDefault1Check );
  159.                 if ( UDialogUtils::GetItemValue( dialog, kUseDefault1Check ) == 1 )
  160.                     UDialogUtils::EnableDialogItem( dialog, kButton1Text, false );
  161.                 else
  162.                     UDialogUtils::EnableDialogItem( dialog, kButton1Text, true );
  163.                 break;
  164.                 
  165.             case kUseDefault2Check:
  166.                 UDialogUtils::ToggleCheckBox( dialog, kUseDefault2Check );
  167.                 if ( UDialogUtils::GetItemValue( dialog, kUseDefault2Check ) == 1 )
  168.                     UDialogUtils::EnableDialogItem( dialog, kButton2Text, false );
  169.                 else
  170.                     UDialogUtils::EnableDialogItem( dialog, kButton2Text, true );
  171.                 break;
  172.                 
  173.             case kUseDefault3Check:
  174.                 UDialogUtils::ToggleCheckBox( dialog, kUseDefault3Check );
  175.                 if ( UDialogUtils::GetItemValue( dialog, kUseDefault3Check ) == 1 )
  176.                     UDialogUtils::EnableDialogItem( dialog, kButton3Text, false );
  177.                 else
  178.                     UDialogUtils::EnableDialogItem( dialog, kButton3Text, true );
  179.                 break;
  180.         }
  181.             
  182.     }
  183.     if ( itemHit == kOKButton )
  184.     {
  185.         
  186.         alertType = UDialogUtils::GetItemValue( dialog, kTypePopup ) - 1;
  187.         
  188.         movable = UDialogUtils::GetItemValue( dialog, kMovableCheck ) == 1;
  189.         
  190.         UDialogUtils::GetItemText( dialog, kErrorText, text );
  191.         UDialogUtils::GetItemText( dialog, kExplainText, desc );
  192.         
  193.         if ( UDialogUtils::GetItemValue( dialog, kUseDefault1Check ) == 1 )
  194.         {
  195.             btn1 = (StringPtr)-1L;
  196.         }
  197.         else
  198.         {
  199.             UDialogUtils::GetItemText( dialog, kButton1Text, button1Text );
  200.             btn1 = button1Text;
  201.         }
  202.         
  203.         if ( UDialogUtils::GetItemValue( dialog, kButton2Check ) == 1 )
  204.         {
  205.             if ( UDialogUtils::GetItemValue( dialog, kUseDefault2Check ) == 1 )
  206.             {
  207.                 btn2 = (StringPtr)-1L;
  208.             }
  209.             else
  210.             {
  211.                 UDialogUtils::GetItemText( dialog, kButton2Text, button2Text );
  212.                 btn2 = button2Text;
  213.             }
  214.         }
  215.         else
  216.             btn2 = nil;
  217.             
  218.         if ( UDialogUtils::GetItemValue( dialog, kButton3Check ) == 1 )
  219.         {
  220.             if ( UDialogUtils::GetItemValue( dialog, kUseDefault3Check ) == 1 )
  221.             {
  222.                 btn3 = (StringPtr)-1L;
  223.             }
  224.             else
  225.             {
  226.                 UDialogUtils::GetItemText( dialog, kButton3Text, button3Text );
  227.                 btn3 = button3Text;
  228.             }
  229.         }
  230.         else
  231.             btn3 = nil;
  232.         
  233.         useHelp = ( UDialogUtils::GetItemValue( dialog, kHelpCheck ) == 1 );
  234.  
  235.             // Finally! Now we can call StandardAlert.
  236.             
  237.         DisposeDialog( dialog );
  238.         
  239.             // I'm not passing a filter proc here. So, if you want to handle
  240.             // update events in the background windows, add one here. I've left that
  241.             // as an exercise for you, the good people of Mac-dom.
  242.             
  243.         param.movable         = movable;
  244.         param.filterProc     = nil;
  245.         param.defaultText     = btn1;
  246.         param.cancelText     = btn2;
  247.         param.otherText     = btn3;
  248.         param.helpButton     = useHelp;
  249.         param.defaultButton = kAlertStdAlertOKButton;
  250.         param.cancelButton     = btn2 ? kAlertStdAlertCancelButton : 0;
  251.         param.position         = 0;
  252.         
  253.         StandardAlert( alertType, text, desc, ¶m, &itemHit );
  254.     }
  255.     else
  256.         DisposeDialog( dialog );
  257. }
  258.